const webSocket = require('ws').Server
const PORT = 1258

//build wsServer 
let wss = new webSocket({
    port: PORT
}, function () {
    console.log("now listen at " + PORT)
})


//listen connection
wss.on('connection', (ws) => {
    ws.on('message', (data) => {
        broadcast(wss,data)
	console.log(data)
    })
})

wss.on('disconnect',()=>{
    console.log('some one out')
})


broadcast = (wss,data)=>{
    wss.clients.forEach((ws)=>{
        ws.send(data);
    })
}
